//
//  WYCHeaderFooterView.m
//  初试
//
//  Created by 中企互联 on 2017/10/17.
//  Copyright © 2017年 李胜军. All rights reserved.
//

#import "WYCPlanHearderFootView.h"

@implementation WYCPlanHearderFootView

+(instancetype)headFootViewTableView:(UITableView *)tableView section:(NSInteger)section
{
    static NSString * Head = @"h";
    WYCPlanHearderFootView * headerFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:Head];
    if (headerFooterView == nil)
    {
        headerFooterView = [[WYCPlanHearderFootView alloc] initWithReuseIdentifier:Head withSection:section];;
    }
    
    return headerFooterView;
    
}

- (void)setGroup:(WYCPlanModel *)group
{
    _group = group;
    double a = [group.amount doubleValue] - [group.alreadyRepaid doubleValue];
    NSString * str = [NSString stringWithFormat:@"%.1f",a];
    NSString *MonthStr = [NSString stringWithFormat:@"待还 %.2f",[str doubleValue]];
    _MonthLabel.text = MonthStr;
    _TimeLabel.text = [NSString stringWithFormat:@"已还 %.2f",[group.alreadyRepaid doubleValue]];
    _MoneyLabel.text = [NSString stringWithFormat:@"%.2f",[group.amount doubleValue]];
    
    WYCLog(@"=========%@",_TimeLabel.text);
}

-(id)initWithReuseIdentifier:(NSString *)reuseIdentifier withSection:(NSInteger)section
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier])
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        //        [self setupItems];
        
        //        UIView * backView = [[UIView alloc] init];
        //        backView.frame = CGRectMake(0, 0, ScreenWidth, 200 * px);
        //        backView.backgroundColor = [UIColor whiteColor];
        //        [self.contentView addSubview:backView];
        //九月账单
        _MonthLabel = [[UILabel alloc] init];
        _MonthLabel.frame = CGRectMake(40 * px, 40 * px, 400 * px, 65 * px);
        //        _MonthLabel.text = @"九月账单";
        _MonthLabel.font = [UIFont systemFontOfSize:BigMiddleFont];
        [self.contentView addSubview:_MonthLabel];
        
        
        //时间日期
        _TimeLabel = [[UILabel alloc] init];
        _TimeLabel.frame = CGRectMake(_MonthLabel.x, CGRectGetMaxY(_MonthLabel.frame) + 20 * px, _MonthLabel.width, 50 * px);
        _TimeLabel.font = [UIFont systemFontOfSize:SmallFont];
        _TimeLabel.textColor = WYCRGBColor(163, 163, 163);
        //        _TimeLabel.text = @"2017/08/13";
        [self.contentView addSubview:_TimeLabel];
        
        
        //金额
        _MoneyLabel = [[UILabel alloc] init];
        _MoneyLabel.frame = CGRectMake(ScreenWidth / 2 - 160 * px, _MonthLabel.y, 320 * px, _MonthLabel.height);
        _MoneyLabel.textAlignment = NSTextAlignmentRight;
        _MoneyLabel.font = [UIFont systemFontOfSize:BigMiddleFont];
        [self.contentView addSubview:_MoneyLabel];
        
        //金额账单
        _NumberLabel = [[UILabel alloc] init];
        _NumberLabel.frame = CGRectMake(_MoneyLabel.x, CGRectGetMaxY(_MoneyLabel.frame) + 20 * px, _MonthLabel.width, _MonthLabel.height);
        _NumberLabel.font = [UIFont systemFontOfSize:WyzFont];
        _NumberLabel.text = @"账单金额";
        _NumberLabel.textAlignment = NSTextAlignmentCenter;
        _NumberLabel.textColor = WYCRGBColor(163, 163, 163);
        [self.contentView addSubview:_NumberLabel];
        
        
        //金额账单
        self.zhongzhibutton = [[UIButton alloc] init];
        self.zhongzhibutton.frame = CGRectMake(CGRectGetMaxX(self.MoneyLabel.frame) + 40 * px, self.MoneyLabel.y, ScreenWidth / 4, self.MoneyLabel.height + self.NumberLabel.height - 60 * px);
        self.zhongzhibutton.backgroundColor = WYCMain;
        self.zhongzhibutton.layer.cornerRadius = 30 * px;
        self.zhongzhibutton.layer.masksToBounds = YES;
        [self.zhongzhibutton setTitle:@"终止计划" forState:UIControlStateNormal];
        self.zhongzhibutton.titleLabel.font = [UIFont systemFontOfSize:BigMiddleFont];
        [self.zhongzhibutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.contentView addSubview:self.zhongzhibutton];
        
        //闭合
        _OpenButton = [[UIButton alloc] init];
        [_OpenButton setImage:[UIImage imageNamed:@"Stop"] forState:UIControlStateNormal];
        // 设置按钮内部的imageView的内容模式为居中
        _OpenButton.imageView.contentMode = UIViewContentModeCenter;
        // 超出边框的内容不需要裁剪
        _OpenButton.imageView.clipsToBounds = NO;
        if (section%2 == 0)  _OpenButton.layer.borderWidth = 0.5;
        _OpenButton.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        
        _OpenButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);//设置控件的那边距
        _OpenButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        _OpenButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;//按钮内容水平靠左
        _OpenButton.frame = CGRectMake(CGRectGetMaxX(_NumberLabel.frame), _MoneyLabel.y, 90 * px, 90 * px);
        //    _OpenButton.backgroundColor = [UIColor redColor];
        [_OpenButton addTarget:self action:@selector(openClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_OpenButton];
    }
    return self;
}

- (void)openClick{
    WYCLogFunc;
    self.group.isOpen = !self.group.isOpen;
    if ([self.delegate respondsToSelector:@selector(reloadTableView)]) {
        [self.delegate reloadTableView];
    }
    
}





-(void)layoutSubviews
{
    [super layoutSubviews];
    self.OpenButton.frame = self.bounds;
}

///**
// *  当一个控件被添加到父控件中就会调用
// */
-(void)didMoveToSuperview
{
    
    if (self.group.isOpen)
    {
        _OpenButton.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
        
    }else{
        _OpenButton.imageView.transform = CGAffineTransformMakeRotation(0);
        
        
    }
}
@end

